﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string constr = "Server=.;user=sa;pwd=123456;database=Students";
            SqlConnection mycon = new SqlConnection(constr);

            try
            {
                
                    
                mycon.Open();
                Console.WriteLine("数据库已打开");
                string sql = "select * from staff";
               
              SqlCommand sqlCommand = new SqlCommand(sql, mycon);
            sqlCommand.CommandTimeout = 2;
              Console.WriteLine("创建对象成功");

            }
            catch (Exception  ex)
            {
                Console.WriteLine(ex.Message .ToString());
            }
            finally
            {
               mycon .Close();
            }
        }
    }
}
